package com.ybear.ybutils.utils.toast;

import android.content.Context;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

public class ToastManage {
    private Build mBuild;

    private ToastManage() { mBuild = new Build(); }
    public static ToastManage get() { return ToastManage.HANDLER.I; }
    private static final class HANDLER { private static final ToastManage I = new ToastManage();}

    public ToastManage setBuild(Build build) {
        mBuild = build;
        return this;
    }

    public Build getBuild() { return mBuild; }

    public ToastX makeText(@NonNull Context context,
                           @Nullable CharSequence s,
                           int duration,
                           @Nullable Build build) {
        return new ToastX( context, build == null ? mBuild : build )
                .setText( s )
                .setDuration( duration );
    }

    public ToastX makeText(@NonNull Context context, @Nullable CharSequence s, int duration) {
        return makeText( context, s, duration, mBuild );
    }

    public ToastX makeText(@NonNull Context context,
                           @StringRes int resId,
                           int duration,
                           @Nullable Build build) {
        return new ToastX( context, build == null ? mBuild : build )
                .setText( resId )
                .setDuration( duration );
    }

    public ToastX makeText(@NonNull Context context, @StringRes int resId, int duration) {
        return makeText( context, resId, duration, mBuild );
    }

    public ToastX makeText(@NonNull Context context, int duration) {
        return makeText( context, null, duration );
    }

    public ToastX makeText(@NonNull Context context) {
        return makeText( context, null, ToastX.LENGTH_SHORT );
    }

    public ToastX makeTextForLong(@NonNull Context context) {
        return makeText( context, null, ToastX.LENGTH_LONG );
    }


    public void showToast(@NonNull Context context,
                          CharSequence s,
                          int duration,
                          @Nullable Build build) {
        makeText( context, s, duration, build ).show();
    }
    public void showToast(@NonNull Context context, CharSequence s, int duration) {
        showToast( context, s, duration, mBuild );
    }

    public void showToast(@NonNull Context context,
                          CharSequence s,
                          @Nullable Build build) {
        showToast( context, s, Toast.LENGTH_SHORT, build );
    }
    public void showToast(@NonNull Context context, CharSequence s) {
        showToast( context, s, Toast.LENGTH_SHORT );
    }

    public void showToast(@NonNull Context context,
                          @StringRes int resId,
                          int duration,
                          @Nullable Build build) {
        showToast( context, context.getString(resId), duration, build );
    }
    public void showToast(@NonNull Context context, @StringRes int resId, int duration) {
        showToast( context, context.getString(resId), duration );
    }

    public void showToast(@NonNull Context context,
                          @StringRes int resId,
                          @Nullable Build build) {
        showToast( context, resId, Toast.LENGTH_SHORT, build );
    }
    public void showToast(@NonNull Context context, @StringRes int resId) {
        showToast( context, resId, Toast.LENGTH_SHORT );
    }

    public void showToastForLong(@NonNull Context context,
                                 CharSequence s,
                                 @Nullable Build build) {
        showToast( context, s, Toast.LENGTH_LONG, build );
    }
    public void showToastForLong(@NonNull Context context, CharSequence s) {
        showToast( context, s, Toast.LENGTH_LONG );
    }

    public void showToastForLong(@NonNull Context context,
                                 @StringRes int resId,
                                 @Nullable Build build) {
        showToast( context, resId, Toast.LENGTH_LONG, build );
    }
    public void showToastForLong(@NonNull Context context, @StringRes int resId) {
        showToast( context, resId, Toast.LENGTH_LONG );
    }
}